﻿using System.Text;
using System;
using System.Security.Cryptography;

namespace _装饰模式
{
    internal class Program
    {
        static void Main(string[] args)
        {
            ConcreteComponent c = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();
            d1.SetComponent(c);
            d2.SetComponent(d1);
            d2.Operation();
        }
    }
 

    abstract class Component
    {
        public abstract void Operation();
    }
    class ConcreteComponent : Component
    {
        public override void Operation()
        {
            Console.WriteLine("具体对象的操作");
        }
    }
    abstract class Decorator : Component
    {
        protected Component component;
        public void SetComponent(Component component)
        {
            this.component = component;
        }
        public override void Operation()
        {
            if (component != null)
            {
                component.Operation();
            }
        }
    }

    class ConcreteDecoratorA : Decorator
    {
        private string addedState;
        public override void Operation()
        {
            base.Operation();
            addedState = "new state";
            Console.WriteLine("具体的装饰对象A的操作");
        }
    }
    class ConcreteDecoratorB : Decorator
    {
        private string addedState;
        public override void Operation()
        {
            base.Operation();
            addedState = "new state";
            Console.WriteLine("具体的装饰对象B的操作");
        }
        public void AddedBehavior()
        {

        }
    }
}
